<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //构造函数+原型链
        // function Dog(name){
        //     this.name = name
        // }
        // Dog.prototype.drink = function(){
        //     console.log(this.name +'在喝水')
        // }
        // let dog = new Dog('laifu')
        // dog.drink()

        //class 
//         class Dog{
//             constructor(name){
//                 this.name = name
//             }
//             drink(){
//                 console.log(this.name+'heshui')
//             }
//         }
//    let dog = new Dog('laifu')
//         dog.drink()

        //class继承
        class Animal{
            constructor(age){
                this.age = age
            }
        }
        //子类 extends 父类
        class Dog extends Animal{
            constructor(name,age){
                //必须执行父类的构造器
                super(age)
                this.name = name
            }
            drink(){
                console.log(this.name+'heshui')
            }
        }
       
   let dog = new Dog('laifu',18)
        dog.drink()

    </script>
</body>
</html>